package org.testis.gui.mvc.model.dynamicmap;

import org.testis.gui.mvc.model.*;
import org.testis.gui.mvc.controller.dynamicmap.DynamicMapTreeController;
import org.testis.utils.tree.MyDefaultMutableTreeNode;
import java.util.LinkedList;

/**
 *
 * @author Cahit Emir Erel
 */
public class DynamicMapTreeModel extends AbstractModel {

    private LinkedList<MyDefaultMutableTreeNode> m_loadedDynamicMaps =
            new LinkedList<MyDefaultMutableTreeNode>();
    private MyDefaultMutableTreeNode m_dynamicMapSelectedNode = null;
    private String m_dynamicMapProperties = "";
    private MyDefaultMutableTreeNode m_source = null;
    private MyDefaultMutableTreeNode m_destination = null;
    private Boolean m_mode = false;

    public DynamicMapTreeModel() {
    }

    public void setDMapCompareMode(Boolean mode) {
        Boolean oldMode = m_mode;
        m_mode = mode;
        if (mode != null) {
            firePropertyChange(DynamicMapTreeController.COMPARE_MODE_ON,
                    oldMode,
                    mode);
        }
    }

    public MyDefaultMutableTreeNode getSource() {
        return m_source;
    }

    public void setSource(MyDefaultMutableTreeNode source) {
        MyDefaultMutableTreeNode oldSource = m_source;
        m_source = source;
        firePropertyChange(DynamicMapTreeController.SOURCE,
                oldSource,
                source);
    }

    public MyDefaultMutableTreeNode getDestination() {
        return m_destination;
    }

    public void setDestination(MyDefaultMutableTreeNode destination) {
        MyDefaultMutableTreeNode oldDestination = m_destination;
        m_destination = destination;
        firePropertyChange(DynamicMapTreeController.DESTINATION,
                oldDestination,
                destination);
    }

    public void setDynamicMapReloadTree(Boolean reload) {
        if (reload != null && reload) {
            firePropertyChange(DynamicMapTreeController.TREE_RELOAD,
                    null,
                    reload);
        }
    }

    public void setDynamicMapRefreshTree(Boolean refresh) {
        if (refresh != null && refresh) {
            firePropertyChange(DynamicMapTreeController.TREE_REFRESH,
                    false,
                    true);
        }
    }

    public void initDefault() {
        setDynamicMapProperties("Welcome to ATOF Dynamic Map Designer");
    }

    public void setDynamicMapSaveTree(MyDefaultMutableTreeNode tree) {
        if (tree != null) {
            firePropertyChange(DynamicMapTreeController.TREE_SAVE,
                    null,
                    tree);
        }
    }

    public void setDynamicMapLoadTree(MyDefaultMutableTreeNode tree) {
        if (tree == null) {
            return;
        }
        if (!m_loadedDynamicMaps.contains(tree)) {
            m_loadedDynamicMaps.add(tree);
        }
        firePropertyChange(DynamicMapTreeController.TREE_LOAD,
                null,
                tree);
    }

    public LinkedList<MyDefaultMutableTreeNode> getDynamicMapLoadTree() {
        return m_loadedDynamicMaps;
    }

    public MyDefaultMutableTreeNode getDynamicMapSelectedNode() {
        return m_dynamicMapSelectedNode;
    }

    public void setDynamicMapSelectedNode(MyDefaultMutableTreeNode selectedNode) {
        MyDefaultMutableTreeNode oldSelectedNode = m_dynamicMapSelectedNode;
        m_dynamicMapSelectedNode = selectedNode;
        firePropertyChange(DynamicMapTreeController.SELECT_DESIGN_PART,
                oldSelectedNode,
                selectedNode);
    }

    public String getDynamicMapProperties() {
        return m_dynamicMapProperties;
    }

    public void setDynamicMapProperties(String properties) {
        if (properties == null) {
            properties = "";
        }
        String oldProperties = m_dynamicMapProperties;
        m_dynamicMapProperties = properties;
        firePropertyChange(DynamicMapTreeController.SHOW_PROPERTIES,
                oldProperties,
                properties);
    }

    public void setDynamicMapDelete(Boolean delete) {
        if (delete != null && delete) {
            firePropertyChange(DynamicMapTreeController.NODE_DELETE,
                    false,
                    true);
        }
    }

    public void setClearSelection(Boolean value) {
        if (value != null && value) {
            firePropertyChange(DynamicMapTreeController.CLEAR_SELECTION_PROPERTY,
                    null,
                    value);
        }
    }

}
    

